import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:liuxlcommon/view/lxl_widget.dart';
import 'package:liuxlcommon/view/my_box.dart';
import 'package:love_newf/app/com/base/L.dart';
import 'package:love_newf/app/com/model/room_data_model.dart';
import 'package:love_newf/app/com/model/room_info_model.dart';
import 'package:love_newf/app/com/model/room_type.dart';
import 'package:love_newf/app/com/util/my_toast.dart';
import 'package:love_newf/app/page/live/child/child_chat/child_chat_view.dart';
import 'package:love_newf/app/page/live/live_logic.dart';
import 'package:love_newf/app/page/live/widget/bottom_options_view.dart';
import 'package:love_newf/app/page/live/widget/live_preview/live_preview.dart';
import 'package:love_newf/generated/assets.dart';
import 'package:love_newf/value/app_const.dart';

bool autoShangMaiValue = false;

class ChildThreePage extends StatelessWidget {
  LiveLogic logic = Get.find<LiveLogic>();

  ChildThreePage({super.key});

  RoomInfoUserRoomVO get userRoomVO =>
      logic.roomInfo.userRoomVO ?? RoomInfoUserRoomVO();

  @override
  Widget build(BuildContext context) {
    return LColumn.eazy([
      topView,
      livePreviewBox,
      LExpand(
          child: LRow.eazy([
        LExpand(child: const ChildChatPage()),
        LColumn.eazy([
          10.lsh,
          LText.easy(
                  logic.isOwner
                      ? "邀请嘉宾"
                      : "申请上麦\n${L.userInfo.sex == 1 ? "20玫瑰/次" : "免费直播"}",
                  12.w,
                  fw5,
                  Colors.white)
              .paddingH(10.w)
              .size(null, 40.w)
              .gradient(const [Color(0xFFFD9B6C), Color(0xFFF46D49)],
                  Alignment.bottomCenter)
              .radius(20.w)
              .center(),
          LExpand(),
        ]).paddingAll(8.w)
      ])),
      const BottomOptionsPage()
    ]).align(Alignment.topLeft).size(double.infinity, double.infinity);
  }

  double previewWidth = Get.width / 2;

  get livePreviewBox {
    if (logic.roomMaisList.isEmpty) return SizedBox();
    return LColumn.eazy([
      LRow.eazy([
        LExpand(),
        livePreview(logic.roomMaisList[0]),
        LColumn.eazy([
          roomTypeBox,
          10.lsh,
          LText.easy("个人数据", 12.w, fw6, Colors.white)
              .center()
              .bgColor(const Color(0xFF9745C1))
              .paddingH(7.w)
              .radius(13.w)
              .size(null, 26.w)
              .onTapL(() {
            toast("未完成");
          }),
          10.lsh,
          autoShangMaiBtn,
          LExpand()
        ])
            .padding(right: 8.w)
            .size(null, previewWidth)
            .flex(1)
            .align(Alignment.centerRight)
      ]),
      LRow.eazy([
        livePreview(logic.roomMaisList[1]),
        livePreview(logic.roomMaisList[2])
      ])
    ]);
  }

  get autoShangMaiBtn => LRow.eazy([
        Transform.scale(
          scale: 0.8, // 缩小到原来的 70%
          child: Switch(
            value: autoShangMaiValue,
            onChanged: (bool value) {
              autoShangMaiValue = value;
              logic.settingAutoShangMai(autoShangMaiValue);
              logic.update();
            },
            activeColor: Colors.green,
            // 激活状态的颜色
            inactiveThumbColor: Colors.red,
            // 未激活时的按钮颜色
            inactiveTrackColor: Colors.grey, // 未激活时的轨道颜色
          ),
        ),
        LText.easy("自动\n上麦", 12.w, null, Colors.white)
      ]);

  get roomTypeBox => LRow.eazy([
        LImage.easy(Assets.liveLove, 14.w, 14.w),
        4.lsw,
        LText.easy(logic.roomInfo.roomType == RoomType.THREE ? "转为专属" : "转为大厅",
            12.w, fw6, Colors.white)
      ])
          .bgColor(const Color(0xFF9745C1))
          .paddingH(7.w)
          .radius(13.w)
          .size(null, 26.w);

  Widget livePreview(RoomDataRoomMais mais) {
    return SizedBox(
        width: previewWidth,
        height: previewWidth,
        child: Stack(
          children: [
            InkWell(
                onTap: () {
                  logic.applyShangMai(mais);
                },
                child: LContainer(
              child: LText.easy(
                      logic.isOwner
                          ? (mais.maiIndex == 2 ? "邀请男嘉宾" : "邀请女嘉宾")
                          : "申请上麦",
                      14.w,
                      null,
                      Colors.white)
                  .radius(17.w)
                  .bgColor(const Color(0x35120C25))
                  .padding(left: 11.w, right: 11.w, top: 6.w, bottom: 6.w),
            ).center().size(double.infinity, double.infinity).bgImg(
                    mais.maiIndex == 2
                        ? Assets.liveMaisMan
                        : Assets.liveMaisWoman)),
            if (mais.status != 0) LivePreviewPage(mais)
          ],
        ));
  }

  get topView => LRow.eazy([
        LRow.eazy([
          LImage.easy(userRoomVO.avatar, 26.w, 26.w, 26.w),
          LColumn.eazy([
            LText.easy(userRoomVO.nick, 12.w, fw5, Colors.white),
            LText.easy(userRoomVO.userCode, 10.w, fw5, Colors.white),
          ]),
          LText.easy("加入粉团", 10.w, fw5, Colors.white)
              .radius(10.w)
              .padding(left: 9.w, right: 9.w, top: 1.w, bottom: 1.w),
        ]).radius(17.w).paddingAll(4.w).bgColor(Color(0x5C000000)),
        LExpand(),
        LImage.easy(Assets.liveExitLive, 22.w, null).paddingH(16.w).onTapL(() {
          logic.exitRoomDialog();
        })
      ]);
}
